/***************************************************************************
 *   Copyright (C) 2005 by xihe                                            *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "ClusterInfo.h"
#include "CodeConverter.h"

extern CodeConverter g2u;

ClusterInfo::ClusterInfo(const QQGroupFriend& rhs) :
    BuddyInfo	( rhs.uid, true),
    externalId	(0x00000000),
    creator	(0x00000000),
    versionId	(0x00000000),
    category	(0x0000),
    clusterType (0x00),
    authType	(0x00)
{}
    

ClusterInfo::ClusterInfo(const GetClusterInfoReplyPacket& rhs) :
    BuddyInfo	( rhs.getUid(), g2u.convert(rhs.getClusterName()), true),
    notice	( rhs.getNotice() ),
    describing	( rhs.getDescribing() ),
    externalId	( rhs.getExternalId( )),
    creator	( rhs.getCreator() ),
    versionId	( rhs.getVersionId() ),
    category	( rhs.getCategory() ),
    clusterType	( rhs.getClusterType() ),
    authType	( rhs.getAuthType() )
{

    typedef GetClusterInfoReplyPacket::Members UidList;
    const UidList& uidlist = rhs.getMembers();
    
    UidList::const_iterator first = uidlist.begin();
    UidList::const_iterator last  = uidlist.end();

    members.erase();
    for (; first != last; ++first) {
	members.insertElement(*first, new FriendInfo(*first));
    }
}

ClusterInfo& ClusterInfo::operator = (const GetClusterInfoReplyPacket& rhs)
{
    nickname    = g2u.convert(rhs.getClusterName());
    //nickname	= rhs.getClusterName();
    notice      = rhs.getNotice();
    describing  = rhs.getDescribing();
    //uid	= rhs.getUid();
    externalId	= rhs.getExternalId();
    versionId   = rhs.getVersionId();
    creator	= rhs.getCreator();
    category	= rhs.getCategory();
    clusterType = rhs.getClusterType();
    authType	= rhs.getAuthType();

    typedef GetClusterInfoReplyPacket::Members UidList;
    const UidList& uidlist = rhs.getMembers();
    
    UidList::const_iterator first = uidlist.begin();
    UidList::const_iterator last  = uidlist.end();

    for (; first != last; ++first) {
	if (NULL == members.getElement(*first)) {
	     members.insertElement(*first, new FriendInfo(*first));
	}
    }
    
    return *this;
}



